using System;
using System.Xml.Serialization;

namespace Triton.Bot.Profiles
{
	[Serializable]
	public abstract class ConditionalProfileElement : ProfileElement
	{
		private string _condition;

		private Func<bool> _conditionExpression;

		[XmlAttribute("Condition")]
		public string ConditionString
		{
			get
			{
				return _condition;
			}
			set
			{
				if (value != _condition)
				{
					_condition = value;
					_conditionExpression = ProfileScripting.GetCondition(value);
				}
			}
		}

		[XmlIgnore]
		public bool Condition => _conditionExpression();

		[XmlIgnore]
		public bool HasCondition => !string.IsNullOrEmpty(ConditionString);
	}
}
